package com.woniu.utils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.beans.BeanUtils;

public class WoniuBeanUtils {
	
	public static <T> T copyObject(Object source,Class<T> type) {
		T obj = null;
		try {
			obj = type.newInstance();
		} catch (InstantiationException | IllegalAccessException e) {
			e.printStackTrace();
		}
		BeanUtils.copyProperties(source, obj);
		return obj;
	}
	
	public static <T> List<T> copyList(@SuppressWarnings("rawtypes") Collection source,Class<T> type) {
		List<T> lists = new ArrayList<>();
		for(Object obj : source) {
			try {
				T t = type.newInstance();
				BeanUtils.copyProperties(obj, t);
				lists.add(t);
			} catch (InstantiationException | IllegalAccessException e) {
				e.printStackTrace();
			}
			
		}
		return lists;
	}

	
	
	
	
	
	
	
}
